package com.example.myapplication.Activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.myapplication.R;

public class F1 extends AppCompatActivity {

    private TextView bmiNumber;
    private TextView bmiStatus;
    Double bmi;
    private ImageView back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_f1);
        initView();
        bmi = getIntent().getDoubleExtra("bmi", 0.0);
        x();

    }

    /*
    判断bmi值范围
     */
    public void x() {

        if (bmi >= 0) {
            if (bmi <= 18.5) {
                bmiNumber.setText(bmi + "");
                bmiStatus.setText("过轻");
                bmiStatus.setTextColor(this.getResources().getColor(R.color.过轻));
                bmiNumber.setTextColor(this.getResources().getColor(R.color.过轻));
            } else if (bmi > 18.5 && bmi <= 24.9) {
                bmiNumber.setText(bmi + "");
                bmiStatus.setText("正常");
                bmiNumber.setTextColor(this.getResources().getColor(R.color.正常));
                bmiStatus.setTextColor(this.getResources().getColor(R.color.正常));
            } else if (bmi > 24.9 && bmi <= 29.9) {
                bmiNumber.setText(bmi + "");
                bmiStatus.setText("过重");
                bmiNumber.setTextColor(this.getResources().getColor(R.color.过重));
                bmiStatus.setTextColor(this.getResources().getColor(R.color.过重));
            } else if (bmi > 29.9 && bmi <= 34.9) {
                bmiNumber.setText(bmi + "");
                bmiStatus.setText("肥胖");
                bmiNumber.setTextColor(this.getResources().getColor(R.color.肥胖));
                bmiStatus.setTextColor(this.getResources().getColor(R.color.肥胖));
            } else {
                bmiNumber.setText(bmi + "");
                bmiStatus.setText("非常肥胖");
                bmiNumber.setTextColor(this.getResources().getColor(R.color.非常肥胖));
                bmiStatus.setTextColor(this.getResources().getColor(R.color.非常肥胖));
            }
        }
    }

    /*
       初始化控件
        */
    private void initView() {
        bmiNumber = (TextView) findViewById(R.id.bmi_number);
        bmiStatus = (TextView) findViewById(R.id.bmi_status);
        back = (ImageView) findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
